package com.jlstu.controller;

import com.jlstu.util.PdfUtil;
import com.jlstu.util.WordUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
public class TestController {

    // http://localhost:8080/exportWordOrPdf?type=1(1是word,2是pdf)
    @GetMapping("/exportWordOrPdf")
    public void exportPdf(HttpServletResponse response, Integer type) {
        Map<String, Object> map = new HashMap<>();

        try {
            map.put("title", "测试招待事前审批及费用结算审批单");
            if (type == 1) {
                WordUtil.exportWord("template.ftl", map, "招待事前审批及费用结算审批单", response);
            } else {
                File file = WordUtil.generateWord("template.ftl", map);
                PdfUtil.covertDocToPdf(file, "招待事前审批及费用结算审批单", response);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
